package msu.ml.data;
import weka.core.*;

/**
 * Classifies probability distributions using a majority rule. The
 * class with the highest probability is chosen.
 *
 * @author Reginald M Mead
 * @version 1.0
 *
 * @see ClassificationRule
 * @see MajorityRule
 */
public class MajorityRule extends ClassificationRule 
{
	/**
	 * Classifies a distribution by choosing the class with 
	 * the greatest probability.
	 *
	 * @param distribution to classify
	 */
	public int getClassFromDistribution(double [] distribution)
	{
		int highIndex = 0;
		for(int i = 1; i < distribution.length; i++)
		{
			if(distribution[i] > distribution[highIndex])
				highIndex = i;
		}
		return highIndex;
	}

	/**
	 * Classifies a set of frequencies by choosing the class with 
	 * the highest frequency.
	 *
	 * @param freq set of frequencies to classify
	 */
	public int getClassFromDistribution(int [] freq)
	{
		int highIndex = 0;
		for(int i = 1; i < freq.length; i++)
		{
			if(freq[i] > freq[highIndex])
				highIndex = i;
		}
		return highIndex;

	}
}
